﻿using UnityEngine;

namespace UnknowWorld.CardGame
{
    /// <summary>
    /// 资源控制
    /// </summary>
    public class ResourceControl : MonoBehaviour
    {
        public static ResourceControl Instance
        {
            get
            {
                if(!instance)
                    instance = new GameObject("ResourceControl", typeof(ResourceControl)).GetComponent<ResourceControl>();
                return instance;
            }
        }

        private static ResourceControl instance;

        private enum Status
        {
            Ready,
            EffectLoaded,
            CardLoaded,
            EnemyLoaded,
        }

        /// <summary>
        /// 加载状态
        /// </summary>
        private Status status = Status.Ready;
        
        /// <summary>
        /// 是否加载成功
        /// </summary>
        public bool IsLoaded
        {
            get 
            {
                return _loaded;
            }
        }

        /// <summary>
        /// 是否加载成功
        /// </summary>
        private bool _loaded; 

        void OnEnable()
        {
            var ep = EffectPool.Instance;
        }

        void Update()
        {
            if (status == Status.Ready && EffectPool.Instance.Loaded)
            {
                status = Status.EffectLoaded;
                var cp = CardPool.Instance;
                Debug.Log("Effect Resource Load Finish");
            }
            else if (status == Status.EffectLoaded && CardPool.Instance.Loaded)
            {
                status = Status.CardLoaded;
                var rp = EnemyPool.Instance;
                Debug.Log("Card Resource Load Finish");
            }
            else if (status == Status.CardLoaded && EnemyPool.Instance.Loaded)
            {
                status = Status.EnemyLoaded;
                _loaded = true;
                Debug.Log("Enemy Resource Load Finish");
            }
        }
    }
}